const Redis = require('ioredis');

// Redis配置
const redisConfig = {
  port: 6379,
  host: '127.0.0.1',
  password: '',
  db: 0,
};

const redis = new Redis(redisConfig);

async function checkRedisData() {
  try {
    console.log('🔍 连接到Redis...');
    
    // 检查连接
    await redis.ping();
    console.log('✅ Redis连接成功');
    
    // 查看所有键
    const keys = await redis.keys('*');
    console.log('\n🔑 Redis中的所有键:');
    keys.forEach(key => {
      console.log(`  ${key}`);
    });
    
    // 查找与插件数据相关的键
    const pluginKeys = keys.filter(key => key.includes('plugin') || key.includes('batch'));
    console.log('\n🔌 插件相关键:');
    for (const key of pluginKeys) {
      const type = await redis.type(key);
      console.log(`  ${key} (${type})`);
      
      if (type === 'string') {
        const value = await redis.get(key);
        console.log(`    值: ${value.substring(0, 100)}${value.length > 100 ? '...' : ''}`);
      } else if (type === 'list') {
        const length = await redis.llen(key);
        console.log(`    长度: ${length}`);
        if (length > 0) {
          const items = await redis.lrange(key, 0, Math.min(2, length - 1));
          items.forEach((item, index) => {
            console.log(`    项目 ${index}: ${item.substring(0, 100)}${item.length > 100 ? '...' : ''}`);
          });
        }
      } else if (type === 'hash') {
        const fields = await redis.hgetall(key);
        console.log(`    字段数量: ${Object.keys(fields).length}`);
        Object.entries(fields).forEach(([field, value]) => {
          console.log(`    ${field}: ${value.substring(0, 50)}${value.length > 50 ? '...' : ''}`);
        });
      }
    }
    
    // 特别检查批次相关的数据
    console.log('\n📦 检查批次数据...');
    const batchKeys = keys.filter(key => key.startsWith('plugin:batch:'));
    for (const key of batchKeys) {
      const batchData = await redis.hgetall(key);
      console.log(`\n批次 ${key}:`);
      Object.entries(batchData).forEach(([field, value]) => {
        console.log(`  ${field}: ${value}`);
      });
    }
    
  } catch (error) {
    console.error('❌ Redis操作出错:', error.message);
  } finally {
    await redis.quit();
  }
}

checkRedisData();